home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / metkit / kbdump.cpp < prev    next >
C/C++ Source or Header  |  1997-06-07  |  4KB  |  123 lines

  1. //    Copyright (C) 1996, 1997 Meta Four Software.  All rights reserved.
  2. //
  3. //  Datafile dump utility sample code, adapted to use bound data
  4. //
  5. //! rev="$Id: kbdump.cpp,v 1.1 1997/05/27 10:42:34 jcw Rel $"
  6.  
  7. #include "m4kit.h"
  8. #include "kbound.h"
  9.  
  10. #include <stdio.h>
  11.  
  12. /////////////////////////////////////////////////////////////////////////////
  13. // This code was taken from the DUMP sample program without any changes
  14.  
  15. static void ViewDisplay(const c4_View& v_, int l_ =0)
  16. {
  17.     c4_String types;
  18.     bool hasData = false, hasSubs = false;
  19.  
  20.         // display header info and collect all data types
  21.     printf("%*s VIEW %5d rows =", l_, "", v_.GetSize());
  22.     for (int n = 0; n < v_.NumProperties(); ++n)
  23.     {
  24.         c4_Property prop = v_.NthProperty(n);
  25.         char t = prop.Type();
  26.  
  27.         printf(" %s:%c", (const char*) prop.Name(), t);
  28.         
  29.         types += t;
  30.     
  31.         if (t == 'V')
  32.             hasSubs = true;
  33.         else
  34.             hasData = true;
  35.     }
  36.     printf("\n");
  37.  
  38.     for (int j = 0; j < v_.GetSize(); ++j)
  39.     {
  40.         if (hasData)    // data properties are all shown on the same line
  41.         {
  42.             printf("%*s %4d:", l_, "", j);
  43.             c4_RowRef r = v_[j];
  44.             c4_Bytes data;
  45.  
  46.             for (int k = 0; k < types.GetLength(); ++k)
  47.             {
  48.                 c4_Property p = v_.NthProperty(k);
  49.  
  50.                 switch (types[k])
  51.                 {
  52.                 case 'I':
  53.                     printf(" %ld", (long) ((c4_IntProp&) p) (r));
  54.                     break;
  55.  
  56.                 case 'F':
  57.                     printf(" %g", (double) ((c4_FloatProp&) p) (r));
  58.                     break;
  59.  
  60.                 case 'D':
  61.                     printf(" %.12g", (double) ((c4_DoubleProp&) p) (r));
  62.                     break;
  63.  
  64.                 case 'S':
  65.                     printf(" '%s'", (const char*) (c4_String)
  66.                                         ((c4_StringProp&) p) (r));
  67.                     break;
  68.  
  69.                 case 'B':
  70.                     (p (r)).GetData(data);
  71.                     printf(" (%db)", data.Size());
  72.                     break;
  73.  
  74.                 default:
  75.                     if (types[k] != 'V')
  76.                         printf(" (%c?)", types[k]);
  77.                 }
  78.             }
  79.  
  80.             printf("\n");
  81.         }
  82.  
  83.         if (hasSubs)    // subviews are then shown, each as a separate block
  84.         {
  85.             for (int k = 0; k < types.GetLength(); ++k)
  86.             {
  87.                 if (types[k] == 'V')
  88.                 {
  89.                     c4_Property prop = v_.NthProperty(k);
  90.  
  91.                     printf("%*s %4d: subview '%s'\n", l_, "", j,
  92.                             (const char*) prop.Name());
  93.  
  94.                     if (l_ > 0 || k > 0)
  95.                     {
  96.                         c4_ViewProp& vp = (c4_ViewProp&) prop;
  97.  
  98.                         ViewDisplay(vp (v_[j]), l_ + 2);
  99.                     }
  100.                 }
  101.             }
  102.         }
  103.     }
  104. }
  105.  
  106. /////////////////////////////////////////////////////////////////////////////
  107.  
  108. int main(int argc, char** argv)
  109. {
  110.         // when called with a file, use that - else use the bound object
  111.     c4_Storage* store = argc > 1 ? new c4_Storage (argv[1], false)
  112.                                  : new c4_BoundStorage;
  113.  
  114.         // this is the same as in the DUMP example
  115.     ViewDisplay(store->Contents().Container());
  116.     
  117.     delete store;
  118.     
  119.     return 0;
  120. }
  121.  
  122. /////////////////////////////////////////////////////////////////////////////
  123.